/*
ID:luongho3
LANG:JAVA
TASK:stall4
*/
import java.io.File;
import java.io.PrintStream;
import java.util.Queue;
import java.util.Scanner;
import java.util.concurrent.ArrayBlockingQueue;


public class stall4 {
	
	public static int nA, nB;
	public static int[][] m = new int[500][500];
	public static int[] matchA = new int[500];
	public static int[] matchB = new int[500];
	public static int[] trace = new int[500];

	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("stall4.in"));
		PrintStream ps = new PrintStream(new File("stall4.out"));
		System.setOut(ps);
		nA = scanner.nextInt();
		nB = scanner.nextInt();
		for (int i=1;i<=nA;++i) {
			int tmp = scanner.nextInt();
			for (int j=1;j<=tmp;++j) {
				int to = scanner.nextInt();
				m[i][to] = 1;
			}
		}
		
		Init();
		
		Solve();
		
		int nMatches = 0;
		for (int i=1;i<=nA;++i) {
			if (matchA[i] != 0) {
				nMatches++;
			}
		}
		
		System.out.println(nMatches);
		ps.close();
	}

	private static void Init() {
		for (int i=1;i<=nA;++i) {
			matchA[i] = 0;
		}
		for (int i=1;i<=nB;++i) {
			matchB[i] = 0;
		}
	}

	private static void Solve() {
		int finish;
		do {
			finish = FindAugmentingPath();
			if (finish != 0) {
				Enlarge(finish);
			}
		} while (finish != 0);
	}

	private static void Enlarge(int finish) {
		do {
			int x = trace[finish];
			int next = matchA[x];
			matchA[x] = finish;
			matchB[finish] = x;
			finish = next;
		} while (finish != 0);
	}

	private static int FindAugmentingPath() {
		for (int i=1;i<=nB;++i) {
			trace[i] = 0;
		}
		
		Queue<Integer> queue = new ArrayBlockingQueue<Integer>(1000);
		for (int i=1;i<=nA;++i) {
			if (matchA[i] == 0) {
				queue.add(i);
			}
		}
		
		while (!queue.isEmpty()) {
			int front = queue.poll();
			for (int i=1;i<=nB;++i) {
				if (trace[i] == 0 && m[front][i] == 1) {
					trace[i] = front;
					if (matchB[i] == 0) {
						return i;
					}
					else {
						queue.add(matchB[i]);
					}
				}
			}
		}
		return 0;
	}
	
}
